package com.example.onlineeducation.viewmodel


import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.data.entity.LoginUserInfoEntity
import com.example.onlineeducation.data.entity.OfflineStudyLiveListEntity
import com.example.onlineeducation.repository.OfflineRepository
import com.yc.jetpacklib.net.YcResult
import kotlinx.coroutines.flow.collectLatest


/**
 * Creator: yc
 * Date: 2021/6/15 18:03
 * UseDes:
 */
class OfflineStudyListAcVM : BaseViewModel() {

    private val mOfflineRepository: OfflineRepository by lazy { OfflineRepository(mApiService) }

    private val _mGetStudyLiveList = MutableLiveData<YcResult<List<OfflineStudyLiveListEntity>?>>()
    val mGetStudyLiveList: LiveData<YcResult<List<OfflineStudyLiveListEntity>?>> = _mGetStudyLiveList

    fun getStudyLiveList(proId: String) = ycLaunch {
        mOfflineRepository.getStudyLiveList(proId).ycHasLoading().collectLatest { result ->
            _mGetStudyLiveList.postValue(result)
        }
    }


    fun getOfflineJoinActiveList(proId: String) = ycLaunch {
        mOfflineRepository.getOfflineJoinActiveList(proId).ycHasLoading().collectLatest { result ->
            _mGetStudyLiveList.postValue(result)
        }
    }
}


